import threading
import json
import threadpool

from dialogue.service.dialogue_storage import dialogueStorage
from dialogue.util.kafka_util import MyKafkaProducer
from dialogue.service.rabbitMq_service import RabbitMQService

pool = threadpool.ThreadPool(15)
my_kafka = MyKafkaProducer()
rabbitMq_ser = RabbitMQService()


def send_data_by_es(session_id, message):
    send_old_data = threading.Thread(
        target=my_kafka.sendMessages, args=(session_id, json.dumps(message, ensure_ascii=False)))
    send_old_data.start()
    # send_old_data = threading.Thread(
    #     target=rabbitMq_ser.publish, args=(session_id, json.dumps(message)))
    # send_old_data.start()


def send_data_by_redis(session_id, workspace_id, dialogue_session):
    if dialogue_session is not None:
        # 推入redis
        send_old_data = threading.Thread(
            target=dialogueStorage.set_dialogue_session, args=(session_id, workspace_id, dialogue_session))
        send_old_data.start()
